package com.alibaba.ai.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.ai.entity.YForum;
import com.alibaba.ai.service.YForumService;


import javax.annotation.Resource;
import java.util.List;

@Controller
public class YForumController {
    @Resource
    private YForumService yForumService;

    @ResponseBody
    @RequestMapping("/getForumListByDay")
    public List<YForum> getForumListByDay() {
        List<YForum> listForum = yForumService.getForumListByDay();
        for (YForum yForum : listForum) {
            System.out.println(yForum);
        }
        return listForum;
    }
    @ResponseBody
    @RequestMapping("/getForumListByWeek")
    public List<YForum> getForumListByWeek() {
        List<YForum> listForum = yForumService.getForumListByWeek();
        for (YForum yForum : listForum) {
            System.out.println(yForum);
        }
        return listForum;
    }

    @ResponseBody
    @RequestMapping("/getForumListByYear")
    public List<YForum> getForumListByYear() {
        List<YForum> listForum = yForumService.getForumListByYear();
        for (YForum yForum : listForum) {
            System.out.println(yForum);
        }
        return listForum;
    }


    @ResponseBody
    @RequestMapping("/getForumList")
    public List<YForum> getForumList() {
        List<YForum> listForum = yForumService.getForumList();
        for (YForum yForum : listForum) {
            System.out.println(yForum);
        }
        return listForum;
    }


    @ResponseBody
    @RequestMapping("/getForumListByLive")
    public List<YForum> getForumListByLive() {
        List<YForum> listForum = yForumService.getForumListByLive();
        for (YForum yForum : listForum) {
            System.out.println(yForum);
        }

        return listForum;
    }

    @ResponseBody
    @RequestMapping("/getForumListByDate")
    public List<YForum> getForumListByDate() {
        List<YForum> listForum = yForumService.getForumListByDate();
        for (YForum yForum : listForum) {
            System.out.println(yForum);
        }
        return listForum;
    }

    //模糊查询操作————精华帖和业主论坛两个页面的搜索模块
    @ResponseBody
    @RequestMapping(value = "/getPostlistByName")
    public JSONObject getPostlistByName(String yForName) {
        List<JSONObject> forumjson = yForumService.getForumlistByName(yForName);
        for (JSONObject JSONObject:forumjson) {
            System.out.println(JSONObject);
        }
        JSONObject j= new JSONObject();
        j.put("list",forumjson);
        return j;
    }
}
